package com.team11.server.controller.admin;

import com.team11.server.service.admin.Admin_InsertKc_Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@CrossOrigin
@RestController
@Api(tags ="管理员接口")
public class Admin_InsertKc_Controller {
    @Autowired
    private Admin_InsertKc_Service admin_insertKc_service;
    @ApiOperation("新增课程表")
    @PostMapping("/InsertKc")
    public String InsertKc(String kcDate,String kcName,String zRTeacher
            ,String kcInTime,String kcOutTime,String kcClassroom,String kcRemarks,@RequestParam(value = "SxTeachers" ,required=false) List<String> SxTeachers){
        HashMap<String,Object> map=new HashMap<>();
        map.put("kcDate",kcDate);
        map.put("kcInTime",kcInTime);
        map.put("kcOutTime",kcOutTime);
        map.put("kcClassroom",kcClassroom);
        map.put("kcName",kcName);
        map.put("zRtName",zRTeacher);
        map.put("kcRemarks",kcRemarks);
        Integer t=admin_insertKc_service.SelHaveKc(map);//查询课程是否存在
        if (t>0){
            return "课程已存在";
        }
        else {
            admin_insertKc_service.InsertSk();//初始化
            Integer skId=admin_insertKc_service.SelNewSk();//查询新增之后的skid
            map.put("skId",skId);
            admin_insertKc_service.InsertKc(map);//新增课程
            admin_insertKc_service.UpdateSk(map);//更新上课表
            for (String sxTeacher : SxTeachers) {
                map.put("sxTeacher", sxTeacher);
                admin_insertKc_service.InsertSxT(map); //更新实训老师信息
                System.out.println("被执行");
            }
        }
        return "执行成功";
    }
}
